<?php
namespace Api;

class Config implements \ArrayAccess
{

    protected $path;

    protected $configs = array();

    public function __construct($path)
    {
        $this->path = $path;
    }

    public function offsetGet($key)
    {
        if (empty($this->configs[$key])) {
            $file = $this->path . '/' . $key . '.php';
            $onfig = require $file;
            $this->configs[$key] = $onfig;
        }
        return $this->configs[$key];
    }

    public function offsetSet($key, $value)
    {
        Throw new \Exception('connot write config file.');
    }

    public function offsetExists($key)
    {
        return isset($this->configs[$key]);
    }

    public function offsetUnset($key)
    {
        unset($this->configs[$key]);
    }
}